<!doctype html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport"
        content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>商品详情</title>
</head>
<body>
<form action="/add_goods" method="post">
  <label for="pid">
    编号:
    <input type="text" name="pid" id="pid">
  </label>
  <br>
  <label for="pname">
    名称:
    <input type="text" name="pname" id="pname">
  </label>
  <br>
  <label for="pdesc">
    简介:
    <input type="text" name="pdesc" id="pdesc">
  </label>
  <br>
  <label for="price">
    价格:
    <input type="number" name="price" id="price">
  </label>
  <br>
  <label for="num">
    数量:
    <input type="number" name="num" id="num" value="1">
  </label>
  <br>
  <button type="submit">加入购物车</button>
</form>
<script src="js/jquery.min.js"></script>
<script !src="">
  let strings = location.href.split("?");
  //pid=p001
  let pid = strings[1].split("=")[1];
  console.log(pid);
  $("#pid").val(pid);
  //
  switch (pid) {
    case "p001":
      $("#pname").val("雷柏机械键盘");
      $("#pdesc").val("雷柏机械键盘");
      $("#price").val(111);
      break;
    case "p002":
      $("#pname").val("联想笔记本电脑");
      $("#pdesc").val("联想笔记本电脑");
      $("#price").val(222);
      break;
    case "p003":
      $("#pname").val("小米6手机");
      $("#pdesc").val("小米6手机");
      $("#price").val(333);
      break;
    case "p004":
      $("#pname").val("华为荣耀8手机");
      $("#pdesc").val("华为荣耀8手机");
      $("#price").val(444);
      break;
    case "p005":
      $("#pname").val("小米手环");
      $("#pdesc").val("小米手环");
      $("#price").val(555);
      break;
    default:
      console.log("请查看商品列表正确性")
  }
</script>
</body>
</html>